package LinkedList;

import java.util.*;


public class Test {

    public static void main(String[] args) {

        MyLinkedList myLinkedList=new MyLinkedList();
        myLinkedList.addFirst(2);
        myLinkedList.addFirst(4);
        myLinkedList.addFirst(2);
        myLinkedList.addFirst(3);
        myLinkedList.addFirst(4);

       myLinkedList.removeAllKey(2);
       myLinkedList.display();

    }

    public static void main6(String[] args) {

        MyLinkedList myLinkedList=new MyLinkedList();
        myLinkedList.addFirst(0);
        myLinkedList.addFirst(1);
        myLinkedList.addFirst(2);
        myLinkedList.addFirst(3);
        myLinkedList.addFirst(4);
        myLinkedList.display();

        System.out.println("   ");
        myLinkedList.remove(77);
        System.out.println(myLinkedList.contains(1));
        myLinkedList.display();


    }

    public int removeElement(int[] nums, int val) {
        int count=0;//记录找到值的个数
        for(int i=0;i<nums.length;i++){
            if(nums[i]!=val){
                nums[count++]=nums[i];
            }
        }

        return count;
    }

    /*
    *
    * 给定一个整数数组 nums，将数组中的元素向右轮转 k 个位置，其中 k 是非负数。



示例 1:

输入: nums = [1,2,3,4,5,6,7], k = 3
输出: [5,6,7,1,2,3,4]
解释:
向右轮转 1 步: [7,1,2,3,4,5,6]
向右轮转 2 步: [6,7,1,2,3,4,5]
向右轮转 3 步: [5,6,7,1,2,3,4]
示例 2:

输入：nums = [-1,-100,3,99], k = 2
输出：[3,99,-1,-100]
解释:
向右轮转 1 步: [99,-1,-100,3]
向右轮转 2 步: [3,99,-1,-100]
 */
    void rotate(int[] nums, int left, int right){
        while(left < right){
            int temp = nums[left];
            nums[left] = nums[right];
            nums[right] = temp;
            left++;
            right--;
        }
    }
    public void rotate(int[] nums, int k) {
        k %= nums.length;
        rotate(nums, 0, nums.length-1);
        rotate(nums, 0, k-1);
        rotate(nums, k, nums.length-1);
    }


    public static void main5(String[] args) {

        int [] Array=new int[]{1,2,3,4,5,6,7};

        Test test=new Test();

        test.rotate(Array,5);

        Iterator I1= Arrays.stream(Array).iterator();

        while (I1.hasNext()){

            System.out.print(I1.next());
        }
    }


  /*  给定一个非负整数 numRows，生成「杨辉三角」的前 numRows 行。

    在「杨辉三角」中，每个数是它左上方和右上方的数的和。

    示例 1:

    输入: numRows = 5
    输出: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]
    示例 2:

    输入: numRows = 1
    输出: [[1]]*/

    public List<List<Integer>> generate(int numRows) {
        //定义了一个二位数组
        List<List<Integer>> ret = new ArrayList<>();

        List<Integer> list = new ArrayList<>();
        list.add(1);

        ret.add(list);

        for (int i = 1; i < numRows; i++) {
            //没循环一次 就是一行
            List<Integer> curRow = new ArrayList<>();
            curRow.add(1);//每一行的第一个元素

            //处理中间的数字
            List<Integer> prevRow = ret.get(i-1);
            for (int j = 1; j < i; j++) {
                int x = prevRow.get(j) + prevRow.get(j-1);
                curRow.add(x);
            }

            //处理最后一个数字
            curRow.add(1);

            ret.add(curRow);
        }
        return ret;
    }

    public static void main4(String[] args) {
        MyLinkedList myLinkedList1=new MyLinkedList();
        myLinkedList1.addFirst(11);
        myLinkedList1.addFirst(12);
        myLinkedList1.addFirst(13);
        myLinkedList1.addFirst(14);
        myLinkedList1.addFirst(15);
        myLinkedList1.addFirst(16);
        myLinkedList1.display();
    }
    public static void main3(String[] args) {
        MyLinkedList myLinkedList=new MyLinkedList();
        myLinkedList.addFirst(11);
        myLinkedList.addFirst(12);
        myLinkedList.addFirst(13);
        myLinkedList.addFirst(14);
        myLinkedList.addFirst(15);
        myLinkedList.addFirst(16);
        myLinkedList.display();

        LinkedList<Integer> list=new LinkedList<>();

        list.addFirst(22);
        list.addFirst(22);
        list.addFirst(22);
        list.addFirst(22);
        Iterator i=list.iterator();
        while (i.hasNext()){
            System.out.println(i.next());
        }
    }
    public static void main2(String[] args) {
        MySingleList mySingleList=new MySingleList();

        mySingleList.addFirst(55);

        mySingleList.addFirst(44);
        mySingleList.addFirst(55);
        mySingleList.addFirst(65);
        mySingleList.addFirst(4);
        mySingleList.addFirst(65);

        mySingleList.display();
       /* mySingleList.removeAllKey(55);
        mySingleList.display();*/


        mySingleList.display(mySingleList.reverseList());





    }
    public static void main1(String[] args) {


        MySingleList singleList=new MySingleList();
//        singleList.display();

        System.out.println(singleList.middleNode().val);

    }
}
